#pragma once
#include "Observer.h"
#include "ClockTimer.h"

class AnalogClock : public Observer
{
public:
	AnalogClock(ClockTimer*);
	virtual ~AnalogClock();
	virtual void Update(Subject*);
	virtual void Draw();

private:
	ClockTimer* subject_;
	HANDLE style_;
};

AnalogClock::AnalogClock(ClockTimer* s)
	:Observer()
{
	subject_ = s;
	subject_->Attach(this);
	style_ = GetStdHandle(STD_OUTPUT_HANDLE);
}

AnalogClock::~AnalogClock()
{
	subject_->Detach(this);
}

void AnalogClock::Update(Subject* theChangedSubject)
{
	if (theChangedSubject == subject_) {
		Draw();
	}
}

void AnalogClock::Draw()
{
	int hour = subject_->GetHour();
	int minute = subject_->GetMinute();
	int sec = subject_->GetSecond();
	SetConsoleTextAttribute(style_, FOREGROUND_INTENSITY | FOREGROUND_RED);
	cout << "Analog: " << hour << ":" << minute << ":" << sec << endl;
}

